package com.dequan.springaiproject.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * DeepSeek 配置类
 * 如何在一个项目中配置不同的大模型
 */
@Configuration
public class DeepSeekConfiguration {

    @Value("${spring.ai.deepseek.base-url}")
    private String deepSeekBaseUrl;

    @Value("${spring.ai.deepseek.api-key}")
    private String deepSeekApiKey;

    @Bean
    public ChatClient deepSeekChatClient() {

        // 1. 创建一个 DeepSeek 的 OpenAiApi
        OpenAiApi deepSeekOpenAiApi = OpenAiApi.builder()
                .apiKey(deepSeekApiKey)
                .baseUrl(deepSeekBaseUrl)
                .build();

        // 2. 创建一个 deepseekChatModel
        OpenAiChatModel deepseekChatModel = OpenAiChatModel.builder()
                .openAiApi(deepSeekOpenAiApi)
                .build();

        // 3. 创建一个 DeepSeek 的 ChatClient
        return ChatClient.builder(deepseekChatModel)
                .defaultOptions(OpenAiChatOptions.builder()
                        .model("deepseek-chat")
                        .temperature(0.7)
                        .build())
                .build();
    }
}